﻿#include "page10.h"
#include <QTextEdit>
#include <QPixmap>
#include <QLabel>
#include <QIcon>
#include <QFont>
#include<QVBoxLayout>
#include<QMessageBox>

Page10::Page10(QWidget* parent) : QWidget(parent)
{
    // 设置窗口大小
    setFixedSize(1280, 720);

    // 设置背景
    QPixmap background(":new/prefix1/bg.jpg");
    QLabel* backgroundLabel = new QLabel(this);
    backgroundLabel->setPixmap(background.scaled(this->size())); // 缩放背景图片以适应窗口大小
    backgroundLabel->setGeometry(0, 0, this->width(), this->height());
    backgroundLabel->lower();

    QPixmap overlayImage(":new/prefix1/newbg.jpg");
            QLabel* overlayLabel = new QLabel(this);
            overlayLabel->setPixmap(overlayImage.scaled(1020, 590)); // 缩放新图片为200x150
            overlayLabel->setGeometry(265, 135, 1020, 590); // 设置新图片的位置和大小
    // 设置按钮的初始Y轴位置
    int yPos = 222;

    // 创建并设置订单按钮
    QIcon icon1(":new/prefix1/order.jpg");
    QIcon icon11(":new/prefix1/order2.jpg");
    orderButton = new QPushButton(this);
    orderButton->setIcon(icon1);
    orderButton->setIconSize(QSize(260, 71));
    orderButton->setFlat(true);
    orderButton->setFixedSize(260, 71);
    orderButton->setGeometry(1, yPos, 260, 71);
    connect(orderButton, &QPushButton::clicked, this, [this](){
        emit orderRequested();
    });
    connect(orderButton, &QPushButton::pressed, this, [this, icon11]() {
        orderButton->setIcon(icon11);
    });
    connect(orderButton, &QPushButton::released, this, [this, icon1]() {
        orderButton->setIcon(icon1);
        emit orderRequested();
    });

    // 调整下一个按钮的Y轴位置
    yPos += 68;

    // 创建并设置生产按钮
    QIcon icon2(":new/prefix1/production.jpg");
    QIcon icon12(":new/prefix1/production2.jpg");
    productionButton = new QPushButton(this);
    productionButton->setIcon(icon2);
    productionButton->setIconSize(QSize(260, 71));
    productionButton->setFlat(true);
    productionButton->setFixedSize(260, 71);
    productionButton->setGeometry(1, yPos, 260, 71);
    connect(productionButton, &QPushButton::clicked, this, [this]() {
        emit productionRequested();
    });
    connect(productionButton, &QPushButton::pressed, this, [this, icon12]() {
        productionButton->setIcon(icon12);
    });
    connect(productionButton, &QPushButton::released, this, [this, icon2]() {
        productionButton->setIcon(icon2);
        emit productionRequested();
    });

    // 调整下一个按钮的Y轴位置
    yPos += 68;

    // 创建并设置财务按钮
    QIcon icon3(":new/prefix1/finance.jpg");
    QIcon icon13(":new/prefix1/finance2.jpg");
    financeButton = new QPushButton(this);
    financeButton->setIcon(icon3);
    financeButton->setIconSize(QSize(260, 71));
    financeButton->setFlat(true);
    financeButton->setFixedSize(260, 71);
    financeButton->setGeometry(1, yPos, 260, 71);
    connect(financeButton, &QPushButton::clicked, this, [this]() {
        emit financeRequested();
    });
    connect(financeButton, &QPushButton::pressed, this, [this, icon13]() {
        financeButton->setIcon(icon13);
    });
    connect(financeButton, &QPushButton::released, this, [this, icon3]() {
        financeButton->setIcon(icon3);
        emit financeRequested();
    });

    // 调整下一个按钮的Y轴位置
    yPos += 68;

    // 创建并设置库存按钮
    QIcon icon4(":new/prefix1/warehouse.jpg");
    QIcon icon14(":new/prefix1/warehouse2.jpg");
    warehouseButton = new QPushButton(this);
    warehouseButton->setIcon(icon4);
    warehouseButton->setIconSize(QSize(260, 71));
    warehouseButton->setFlat(true);
    warehouseButton->setFixedSize(260, 71);
    warehouseButton->setGeometry(1, yPos, 260, 71);
    connect(warehouseButton, &QPushButton::clicked, this, [this]() {
        emit storeRequested();
    });
    connect(warehouseButton, &QPushButton::pressed, this, [this, icon14]() {
        warehouseButton->setIcon(icon14);
    });
    connect(warehouseButton, &QPushButton::released, this, [this, icon4]() {
        warehouseButton->setIcon(icon4);
        emit storeRequested();
    });


    // 调整下一个按钮的Y轴位置
    yPos += 68;

    // 创建并设置帮助按钮
    QIcon icon6(":new/prefix1/operationGuide.jpg");
    QIcon icon16(":new/prefix1/operationGuide2.jpg");
    helpButton = new QPushButton(this);
    helpButton->setIcon(icon16);
    helpButton->setIconSize(QSize(260, 71));
    helpButton->setFlat(true);
    helpButton->setFixedSize(260, 71);
    helpButton->setGeometry(1, yPos, 260, 71);
    connect(helpButton, &QPushButton::clicked, this, [this]() {
        emit pageRequested10();
    });
    connect(helpButton, &QPushButton::pressed, this, [this, icon6]() {
        helpButton->setIcon(icon6);
    });
    connect(helpButton, &QPushButton::released, this, [this, icon16]() {
        helpButton->setIcon(icon16);
        emit pageRequested10();
    });

    // 调整下一个按钮的Y轴位置
    yPos += 68;

    // 创建并设置连接按钮
    QIcon icon7(":new/prefix1/connect.jpg");
    QIcon icon17(":new/prefix1/connect2.jpg");
    connectButton = new QPushButton(this);
    connectButton->setIcon(icon7);
    connectButton->setIconSize(QSize(260, 71));
    connectButton->setFlat(true);
    connectButton->setFixedSize(260, 71);
    connectButton->setGeometry(1, yPos, 260, 71);
    connect(connectButton, &QPushButton::clicked, this, [this]() {
        emit pageRequested13();
    });
    connect(connectButton, &QPushButton::pressed, this, [this, icon17]() {
        connectButton->setIcon(icon17);
    });
    connect(connectButton, &QPushButton::released, this, [this, icon7]() {
        connectButton->setIcon(icon7);
        emit pageRequested13();
    });
    yPos += 68;

    // 创建并设置添加员工按钮
    QIcon icon5(":new/prefix1/tianjiayuangong01.jpg");
    QIcon icon15(":new/prefix1/tianjiayuangong02.jpg");
    addEmployeeButton = new QPushButton(this);
    addEmployeeButton->setIcon(icon5);
    addEmployeeButton->setIconSize(QSize(260, 71));
    addEmployeeButton->setFlat(true);
    addEmployeeButton->setFixedSize(260, 71);
    addEmployeeButton->setGeometry(1, yPos, 260, 71);
    connect(addEmployeeButton, &QPushButton::clicked, this, [this]() {
        emit addEmployeeRequested();
    });



    // 创建返回按钮
        frontButton = new QPushButton(u8"", this);
        frontButton->setGeometry(1050,0,170,55); // 调整此位置以适应屏幕
        frontButton->setStyleSheet("QPushButton {"
                                 " border: none; "
                                 "background-image: url(:new/prefix1/tuichudenglu.jpg); "
                                 "background-repeat: no-repeat; "
                                 "background-position: center; }");


        connect(frontButton, &QPushButton::pressed, this, [this]() {
            frontButton->setStyleSheet("QPushButton {"
                                     " border: none; "
                                     "background-image: url(:/new/prefix1/tuichudenglu2.jpg); "
                                     "background-repeat: no-repeat; "
                                     "background-position: center; }");
        });
        connect(frontButton, &QPushButton::released, this, [this]() {
            frontButton->setStyleSheet("QPushButton {"
                                     " border: none; "
                                     "background-image: url(:/new/prefix1/tuichudenglu.jpg); "
                                     "background-repeat: no-repeat; "
                                     "background-position: center; }");
        });

   connect(frontButton, &QPushButton::clicked, this, &Page10::onFrontButtonClicked);
   QVBoxLayout* backLayout = new QVBoxLayout(this);
   setLayout(backLayout);


    // 创建并设置用户指南文本
    QTextEdit* guideTextEdit = new QTextEdit(this);
    guideTextEdit->setStyleSheet(
        "QTextEdit { background: transparent; color: black; border: none; padding: 10px; font-family: 'Arial'; font-size: 24px; }"
        "QTextEdit p { margin: 0; padding: 0; }"
        "QTextEdit h1 { font-size: 26px; font-family: 'Arial Black'; }"
    );

    guideTextEdit->setGeometry(260, 135, 1020, 590); // 根据需要调整位置和大小

    guideTextEdit->setHtml(
        "<h1>1. 订单：</h1>"
        "<p>单击“订单”按钮查看历史订单。</p>"
        "<p>单击“新增订单”添加新订单（财务界面会相应增加收款记录）</p>"
        "<h1>2. 生产：</h1>"
        "<p>单击“生产”按钮查看各季度生产状态。</p>"
        "<h1>3. 财务：</h1>"
        "<p>单击“财务”按钮查看收支情况。</p>"
        "<p>单击“收支”按钮查看历史收支记录(包含收款、支出、付款)</p>"
        "<p>单击“添加收款”为相应编号订单添加尾款</p>"
        "<h1>4. 仓库：</h1>"
        "<p>单击“仓库”查看当前库存概况。</p>"
        "<p>单击“入库”为相应种类货物添加库存</p>"
        "<h1>5. 添加员工：</h1>"
        "<p>此功能只有管理员账号可以使用</p>"
        "<p>单击“添加员工”按钮添加新员工信息。</p>"
        "<p>单击“公司人员”查看所有人的账户信息</p>"
        "<h1>6. 操作指南：</h1>"
        "<p>单击“操作指南”按钮查看操作指南。</p>"
        "<h1>7. 连接：</h1>"
        "<p>单击“连接”按钮进行设备或系统连接。</p>"
    );


    guideTextEdit->setReadOnly(true); // 设置文本框为只读
}

void Page10::financeHide()
{
    // 隐藏财务按钮
    financeButton->setVisible(false);
}

void Page10::signuphide()
{
    // 隐藏添加员工按钮
    addEmployeeButton->setVisible(false);
}
void Page10::onFrontButtonClicked()
{
    QMessageBox msgBox;
    msgBox.setText("确定退出登录吗?");
    msgBox.setWindowTitle("退出登录");
    msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
    msgBox.button(QMessageBox::Ok)->setText("确认");
    msgBox.button(QMessageBox::Cancel)->setText("取消");
    msgBox.setStyleSheet(
        "QMessageBox {"
        "  background-color: #FFFFFF;"
        "}"
        "QMessageBox QLabel {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  color: black;"
        "}"
        "QMessageBox QPushButton {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  background-color: #0093D1;"
        "  color: white;"
        "}"
    );

    if (msgBox.exec() == QMessageBox::Ok) {
        emit pageRequested1();
    }
}
